﻿Imports System
Imports System.Globalization
Imports System.Reflection

Namespace System.Workflow.Activities
    Friend NotInheritable Class ExtendedPropertyInfo
        Inherits PropertyInfo
        ' Methods
        Friend Sub New(ByVal propertyInfo As PropertyInfo, ByVal getValueHandler As GetValueHandler)
            Me.realPropertyInfo = propertyInfo
            Me.OnGetValue = getValueHandler
        End Sub

        Public Overrides Function GetAccessors(ByVal nonPublic As Boolean) As MethodInfo()
            Return Me.realPropertyInfo.GetAccessors(nonPublic)
        End Function

        Public Overrides Function GetCustomAttributes(ByVal inherit As Boolean) As Object()
            Return Me.realPropertyInfo.GetCustomAttributes(inherit)
        End Function

        Public Overrides Function GetCustomAttributes(ByVal attributeType As Type, ByVal inherit As Boolean) As Object()
            Return Me.realPropertyInfo.GetCustomAttributes(attributeType, inherit)
        End Function

        Public Overrides Function GetGetMethod(ByVal nonPublic As Boolean) As MethodInfo
            Return Me.realPropertyInfo.GetGetMethod(nonPublic)
        End Function

        Public Overrides Function GetIndexParameters() As ParameterInfo()
            Return Me.realPropertyInfo.GetIndexParameters
        End Function

        Public Overrides Function GetSetMethod(ByVal nonPublic As Boolean) As MethodInfo
            Return Me.realPropertyInfo.GetSetMethod(nonPublic)
        End Function

        Public Overrides Function GetValue(ByVal obj As Object, ByVal invokeAttr As BindingFlags, ByVal binder As Binder, ByVal index As Object(), ByVal culture As CultureInfo) As Object
            If (Not Me.OnGetValue Is Nothing) Then
                Return Me.OnGetValue.Invoke(Me, obj)
            End If
            Return Nothing
        End Function

        Public Overrides Function IsDefined(ByVal attributeType As Type, ByVal inherit As Boolean) As Boolean
            Return Me.realPropertyInfo.IsDefined(attributeType, inherit)
        End Function

        Public Overrides Sub SetValue(ByVal obj As Object, ByVal value As Object, ByVal invokeAttr As BindingFlags, ByVal binder As Binder, ByVal index As Object(), ByVal culture As CultureInfo)
            Me.realPropertyInfo.SetValue(obj, value, invokeAttr, binder, index, culture)
        End Sub


        ' Properties
        Public Overrides ReadOnly Property Attributes As PropertyAttributes
            Get
                Return Me.realPropertyInfo.Attributes
            End Get
        End Property

        Public Overrides ReadOnly Property CanRead As Boolean
            Get
                Return Me.realPropertyInfo.CanRead
            End Get
        End Property

        Public Overrides ReadOnly Property CanWrite As Boolean
            Get
                Return Me.realPropertyInfo.CanWrite
            End Get
        End Property

        Public Overrides ReadOnly Property DeclaringType As Type
            Get
                Return Me.realPropertyInfo.DeclaringType
            End Get
        End Property

        Public Overrides ReadOnly Property Name As String
            Get
                Return Me.realPropertyInfo.Name
            End Get
        End Property

        Public Overrides ReadOnly Property PropertyType As Type
            Get
                Return Me.realPropertyInfo.PropertyType
            End Get
        End Property

        Public Overrides ReadOnly Property ReflectedType As Type
            Get
                Return Me.realPropertyInfo.ReflectedType
            End Get
        End Property


        ' Fields
        Private OnGetValue As GetValueHandler
        Private realPropertyInfo As PropertyInfo
    End Class
End Namespace

